<template>
  <!-- 主页布局 -->
  <el-container class="layout_container">
    <!-- 头部区域 -->
    <el-header>
      <!-- 左侧：logo区 -->
      <div>
        <img src="../assets/img/ht_logo.png" height="48" alt="">
      </div>
      <!-- 右侧：退出区 -->
      <div style="display: flex;align-items: center;">
        <el-tag v-if="$store.state.userInfo.username" style="height: auto; padding: .3125rem .625rem;font-size: large;margin-right: 1.875rem;">
          {{ $store.state.userInfo.username }},欢迎您</el-tag>
        <el-tag v-else type="danger" @click="$router.push('/login')" style="cursor: pointer;height: auto; padding: .3125rem .625rem;font-size: large;margin-right: 1.875rem;">
          请登录</el-tag> 
        <el-button type="info" @click="logout">退出登录</el-button>
      </div>

    </el-header>
    <!-- 主体区域 -->
    <el-container>
      <!-- 左侧导航区 -->
      <el-aside width="200px">
        <el-menu default-active class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
          background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" router>
          <!-- 一级菜单 -->
          <!-- <el-submenu index="1"> -->
          <el-menu-item index="/welcome">
            <!-- 提示标题 -->
            <template slot="title">
              <i class="el-icon-s-home"></i>
              <span>主页</span>
            </template>
          </el-menu-item>
          <el-submenu v-for="menu in this.$global.menuList" v-if="menu.menuStatus == 1 && menu.menuType == 1"
            :key="menu.menuId" :index="menu.label">
            <!-- 提示标题 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="menu.icon"></i>
              <!-- 文本 -->
              <span>{{ menu.label }}</span>
            </template>
            <!-- 二级菜单模板 -->
            <el-menu-item v-for="child in menu.children" v-if="child.menuStatus == 1 && child.menuType == 2"
              :index="child.menuURL" :key="child.menuId">
              <template slot="title">
                <!-- 图标 -->
                <i :class="child.icon"></i>
                <!-- 文本 -->
                <span>{{ child.label }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体内容 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      username: "test"
    }
  },
  methods: {
    logout() {
      // 清除token
      window.sessionStorage.clear();
      this.$global.menuList = [];
      // 跳转到登录页面
      this.$router.push("/login");
    }
  }
};
</script>

<style>
.layout_container {
  height: 100%;
}

.el-header {
  background-color: #007d71;
  color: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-aside {
  background-color: #222d32;
}

.el-main {
  background-color: #f5f5f5;
}
</style>